package com.learn.cloud.validator.annotation;


import com.learn.cloud.validator.constraints.FileExtensionValidator;
import jakarta.validation.Constraint;
import jakarta.validation.Payload;

import java.lang.annotation.*;

import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
 * @description: 文件拓展校验
 * @author: cong zhi
 * @createDate: 2022/2/6 16:48
 * @updateUser: cong zhi
 * @updateDate: 2022/2/6 16:48
 * @updateRemark: 修改内容
 * @version: v1.0
 */
@Documented
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = {FileExtensionValidator.class})
public @interface ExtensionValidation {
    /**
     * 默认错误消息
     */
    String message() default "File Suffix error";

    /**
     * 支持枚举列表验证
     */
    Class<?> value();

    /**
     * 分组
     *
     * @return
     */
    Class<?>[] groups() default {};

    /**
     * 负载
     *
     * @return
     */
    Class<? extends Payload>[] payload() default {};

    /**
     * @return the extension the annotated string must match, e.g. pdf . Per default any mime type  is allowed
     */
    String[] extensions() default {"*"};

    @Target({ElementType.FIELD, ElementType.PARAMETER})
    @Retention(RUNTIME)
    @Documented
    @interface List {
        ExtensionValidation[] value();
    }
}
